package com.xjm.ips.controller.personnel;

import com.xjm.ips.entity.*;
import com.xjm.ips.service.AdiustSalaryService;
import com.xjm.ips.service.DepartmentService;
import com.xjm.ips.service.EmployeeBasiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/personnel/salary")
public class PersonnelSalaryController {
    @Autowired
    private AdiustSalaryService adiustSalaryService;
    @Autowired
    private EmployeeBasiService employeeBasiService;
    @Autowired
    private DepartmentService departmentService;

    @GetMapping("/")
    public MyPage getAdjustSalaries(@RequestParam(defaultValue = "1") Integer pageNo,
                                        @RequestParam(defaultValue = "10") Integer pageSize,
                                     AdjustSalary adjustSalary){
        return adiustSalaryService.getEmployeeWithSalaryInner(pageNo,pageSize,adjustSalary);
    }

    @PostMapping("/searchadjustsalaries")
    public MyPage searchAdjustSalaries(@RequestParam(defaultValue = "1") Integer pageNo,
                                       @RequestParam(defaultValue = "10") Integer pageSize,
                                       @RequestBody(required = false) AdjustSalary adjustSalary) {
        return adiustSalaryService.getEmployeeWithSalaryInner(pageNo, pageSize, adjustSalary);
    }

    @GetMapping("/getempinfo/{jobNo}")
    public List<Employee> getEmpInfo(@PathVariable String jobNo){
        return employeeBasiService.getInnerEmpWithSalary(jobNo);
    }


    @GetMapping("/getalldepartments")
    public List<Department> getAllDepartments(){
        return departmentService.getAllDepartments();
    }

    @PutMapping("/")
    public AjaxJson updateAdjustSalary(@RequestBody AdjustSalary adjustSalary){
        if(adiustSalaryService.updateAdjustSalary(adjustSalary)==1){
            return AjaxJson.ok("更新员工调薪成功!");
        }
        return AjaxJson.error("更新员工调薪失败!");
    }

    @PostMapping("/")
    public AjaxJson addAdjustSalary(@RequestBody AdjustSalary adjustSalary){
        if(adiustSalaryService.addAdjustSalary(adjustSalary)==1){
            return AjaxJson.ok("新增员工调薪成功!");
        }
        return AjaxJson.error("新增员工调薪失败!");
    }

    @DeleteMapping("/{id}")
    public AjaxJson deleteAdjustSalary(@PathVariable Integer id){
        if(adiustSalaryService.deleteAdjustSalary(id)==1){
            return AjaxJson.ok("删除员工调薪信息成功!");
        }
        return AjaxJson.error("删除员工调薪信息失败!");
    }

    @GetMapping("/getnewestsalary/{eid}")
    public AdjustSalary getNewestSalary(@PathVariable Integer eid){
        return adiustSalaryService.getNewestSalary(eid);
    }
}
